﻿using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Runtime.Serialization;
using System.Collections;
using System.Data;
using System.ComponentModel;
using System.Data.OracleClient;
namespace INTEX.DataBase.Tools
{
    public partial class INTEXDBC
    {
        public void MapKUNDVER(ref DataRow dwLocal, DataRow dwData)
        {
            BlindMap(ref dwLocal, dwData);
        }
        public void InsertKUNDVER(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            or1 = OracleDB.CreateCommand();
            DataSet result = new DataSet();
            or1.CommandText = "INSERT INTO KUNDVER(KDVMANDANT, KDVKUNDNR, KDVVB, KDVVG, KDVSTAKZ, KDVSTADAT, KDVWAEHRSL, KDVZAHLBED, KDVEKON, KDVKDVKL, KDVVALUTA, KDVSTEUER, KDVLIEFBED, KDVLANDU, KDVPLZU, KDVORTU, KDVBZU, KDVBZBEZU, KDVCOUNTRY, KDVCITY, KDVPREISGRP, KDVMINDST, KDVSTDBON, KDVLIEFKOMP, KDVLIEFAUTO, KDVABNGRP, KDVABSSCHL, KDVMUSTER, KDVKOLLZYKL, KDVBONVON, KDVBONIN, KDVBONBIS, KDVABRVB, KDVABRVG, KDVRABABRKZ, KDVBONABRKZ, KDVGBABRKZ, KDVFBABRKZ, KDVVBABRKZ, KDVGABONA, KDVGABONP, KDVFIXBONP, KDVVORBONP, KDVRABART1, KDVRABPROZ1, KDVRABART2, KDVRABPROZ2, KDVRABART3, KDVRABPROZ3, KDVRABART4, KDVRABPROZ4, KDVRABART5, KDVRABPROZ5, KDVBONWE1, KDVBONP1, KDVBONWE2, KDVBONP2, KDVBONWE3, KDVBONP3, KDVBONWE4, KDVBONP4, KDVBONWE5, KDVBONP5, KDVBONWE6, KDVBONP6, KDVBONWE7, KDVBONP7, KDVBONWE8, KDVBONP8, KDVBONWE9, KDVBONP9, KDVBONWE10, KDVBONP10, KDVUMSGR, KDVDISTRWEG, KDVSTATGEB, KDVSACHB, KDVVORBONV1, KDVVORBONV2, KDVVORBONV3, KDVBONLDAT, KDVVBONLDAT, KDVZUREGEL, KDVZEITRAUM, KDVWOCHTAG, KDVKZVORW, KDVMONTAG1, KDVMONTAG2, KDVDATLSR, KDVVTRNR1, KDVVTRNR2, KDVVTRNR3, KDVVTRNR4, KDVAZVERB, KDVBASIS, KDVSPLITT, KDVMEEH, KDVAUFMEEH, KDVABRUF, KDVZESSIO, KDVMAXWERT, KDVPREH, KDVFBPROV, KDVSPLKEY, KDVFILLER, KDVAENDZL, KDVAENDBEN, KDVAENDDAT, KDVNEUBEN, KDVNEUDAT)"
                + " VALUES (:KDVMANDANT, :KDVKUNDNR, :KDVVB, :KDVVG, 'A', 20100121, 'RMB', 'STD', '        ', '   ', 0, '17%', 'EXW', '   ', '            ', '                                        ', '  ', '             ', '    ', '    ', 'SA      ', '1', '        ', 'N', 'N', '   ', '   ', 0, '                         ', 0, 0, 0, '   ', '   ', ' ', ' ', ' ', ' ', ' ', 0, 0, 0, 0, '   ', 0, '   ', 0, '   ', 0, '   ', 0, '   ', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, '   ', '   ', 'INTEXV  ', 0, 0, 0, 0, 0, 'J', ' ', '0', 'N', '00', '00', 20130105, '        ', '        ', '        ', '        ', '0', ' ', ' ', '   ', '   ', 'N', ' ', 0, '   ', ' ', ' ', '                                                                                                                          ', 16, 'SUNLV   ', 20130105, 'INTEXE  ', 20100121)";
            or1.Parameters.Add("KDVMANDANT", OracleType.NVarChar).Value = dwData["KDVMANDANT"].ToString();
            or1.Parameters.Add("KDVKUNDNR", OracleType.NVarChar).Value = dwData["KDVKUNDNR"].ToString();
            or1.Parameters.Add("KDVVB", OracleType.NVarChar).Value = dwData["KDVVB"].ToString();
            or1.Parameters.Add("KDVVG", OracleType.NVarChar).Value = dwData["KDVVG"].ToString();
            Connect2Proxy(or1);
        }
        public DataSet QueryKUNDADR(DataRow dwData, int option = 1)
        {
            DataSet setReturn = new DataSet();
            DataSet setResult = new DataSet();
            OracleCommand or1;
            
                or1 = OracleDB.CreateCommand();
                switch (option)
                {
                    case 0:
                        or1.CommandText = "SELECT * FROM KUNDADR WHERE  ROWNUM<2 ";
                        break;
                    case 1:
                        or1.CommandText = "SELECT * FROM KUNDADR   WHERE "
                                + " KDAKUNDNR = :KDAKUNDNR";
                        or1.Parameters.Add("KDAKUNDNR", OracleType.NVarChar).Value = dwData["KDAKUNDNR"].ToString();
                        break;
                    case 2:
                        or1.CommandText = "SELECT KR.* FROM VVLIEF JOIN KUNDADR   KR ON VVKUNDNRE= KDAKUNDNR AND KDAADRSL=VVADRSLL "
                        + " WHERE VVMANDANT=:VVMANDANT AND VVLIEFSCH = :VVLIEFSCH";
                        or1.Parameters.Add("VVMANDANT", OracleType.NVarChar).Value = dwData["VVMANDANT"].ToString();
                        or1.Parameters.Add("VVLIEFSCH", OracleType.NVarChar).Value = dwData["VVLIEFSCH"].ToString();
                        break;
                    case 3:
                        or1.CommandText = "SELECT DISTINCT VVLIEFSCH,P.* FROM KUNDADR P JOIN VVLIEF ON KDAKUNDNR=VVKUNDNRE AND KDAADRSL=VVADRSLL   WHERE  VVNEUDAT>='" + dwData["DSTART"].ToString() + "' AND VVNEUDAT<='" + dwData["DEND"].ToString() + "' AND VVSTATUS IN (" + dwData["C20"].ToString() + ")"; 
                        break;                        
                    default:
                        break;
                }

                setResult = Connect2Proxy(or1);
                if (setResult.Tables.Count > 0)
                {
                    setResult.Tables[0].TableName = "KUNDADR";
                }
                setReturn.Merge(setResult);
          
            return setReturn;
        }
    }
}
